//
//  AudioBookDetailViewController.m
//  FunRead
//
//  Created by  King on 15/5/27.
//  Copyright (c) 2015年 华东伟. All rights reserved.
//

#import "AudioBookDetailViewController.h"
#import "SANetWorkingTask.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "AudioBookDetailCell.h"
#import "AudioBookDetailModel.h"

@interface AudioBookDetailViewController ()
@property (nonatomic, retain) NSMutableArray *collectionArray;
@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) UIView *HeaderView;
@property (nonatomic, retain) NSMutableDictionary *headerDic;
@property (nonatomic, retain) UIView *ContentView;


@end

@implementation AudioBookDetailViewController
- (void)dealloc
{
    [_id release];
    [_name release];
    [_collectionArray release];
    [_collectionView release];
    [_HeaderView release];
    [_headerDic release];
    [_ContentView release];

    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.name;
    [self startConnection];
    
    
    
    
}

#pragma mark - 网络请求
- (void)startConnection
{
    __block AudioBookDetailViewController *detail = self;
    NSString *str = [NSString stringWithFormat:@"http://app.9nali.com/961/albums/%@?page_id=1&isAsc=true&device=iPad&version=1.1.2", self.id];
    [SANetWorkingTask request:str parmater:nil block:^(NSDictionary *result) {
        detail.headerDic = [result objectForKey:@"album"];
        
        _collectionArray = [result objectForKey:@"list"];
        
        [self createHeaderView];
        
    }];
}
#pragma mark - 建立HeaderView
- (void)createHeaderView
{
    // 设置当前页面背景图片
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [backImage sd_setImageWithURL:[NSURL URLWithString:[self.headerDic objectForKey:@"coverLarge"]]placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    [self.view addSubview:backImage];
    [backImage release];
    
    
    self.HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 6.0)];
    _HeaderView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    // HeaderView上添加Header信息
    UIImageView *HeaderImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, self.HeaderView.frame.size.height - 20, self.HeaderView.frame.size.height - 20)];
    [HeaderImage sd_setImageWithURL:[NSURL URLWithString:[self.headerDic objectForKey:@"coverSmall"]]];placeholderImage:[UIImage imageNamed:@"1.jpg"];
    [_HeaderView addSubview:HeaderImage];
    [HeaderImage release];
    
    UIImageView *smallLogo = [[UIImageView alloc] initWithFrame:CGRectMake(self.HeaderView.frame.size.height - 20 + 20, 12, 20, 20)];
    
    [smallLogo sd_setImageWithURL:[NSURL URLWithString:[_headerDic objectForKey:@"smallLogo"]] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    smallLogo.layer.cornerRadius = 10;
    smallLogo.layer.masksToBounds = YES;
    [_HeaderView addSubview:smallLogo];
    [smallLogo release];
    
    UILabel *nickname = [[UILabel alloc] initWithFrame:CGRectMake(self.HeaderView.frame.size.height - 20 + 45, 10, self.view.frame.size.width, (self.HeaderView.frame.size.height - 20) / 3.0)];
    nickname.text = [NSString stringWithFormat:@"%@  发布", [self.headerDic objectForKey:@"nickname"]];
    nickname.textColor = [UIColor whiteColor];
    [_HeaderView addSubview:nickname];
    [nickname release];
    
    UILabel *tracks = [[UILabel alloc] initWithFrame:CGRectMake(self.HeaderView.frame.size.height - 20 + 30, (self.HeaderView.frame.size.height - 20) / 3.0 + 10, self.view.frame.size.width, (self.HeaderView.frame.size.height - 20) / 3.0)];
    tracks.textColor = [UIColor whiteColor];
    tracks.text = [NSString stringWithFormat:@"节目数：%@", [_headerDic objectForKey:@"tracks"]];
    [_HeaderView addSubview:tracks];
    [tracks release];
    
    [self.view addSubview:_HeaderView];
    [_HeaderView release];
    
    
    NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"列表",@"简介",nil];
    //初始化UISegmentedControl
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    segmentedControl.frame = CGRectMake(0, self.view.frame.size.height / 6.0, self.view.frame.size.width, 50.0);
//    segmentedControl.selectedSegmentIndex = 0;//设置默认选择项索引
    segmentedControl.tintColor = [UIColor lightGrayColor];

    segmentedControl.backgroundColor = [UIColor whiteColor];
    segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;//设置样式
    // 点击后是否恢复原样
    segmentedControl.momentary = YES;
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentedControl];
    [segmentedControl release];
}
// segenment点击方法
- (void)segmentAction:(UISegmentedControl *)seg
{
    switch (seg.selectedSegmentIndex) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            [self createContentView];
        }
            break;
        default:
            break;
    }
}

#pragma mark - 建立CollectView
- (void)createCollectView
{
    
    
    
}
#pragma mark - 建立ContentView
- (void)createContentView
{
    self.ContentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 6.0 + 50, self.view.frame.size.width, self.view.frame.size.height)];
    _ContentView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.8];
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width - 10, self.view.frame.size.height - (self.view.frame.size.height / 6.0 + 50) - 10)];
    contentLabel.numberOfLines = 0;
    contentLabel.textColor = [UIColor grayColor];
    contentLabel.text = [_headerDic objectForKey:@"intro"];
    [_ContentView addSubview:contentLabel];
    [contentLabel release];
    
    [self.view addSubview:_ContentView];
    [_ContentView release];
    
}

@end
